#include "Vector3D.h"

Vector3D::Vector3D()
{
	this->x = 0;
	this->y = 0;
	this->z = 0;
}
Vector3D::Vector3D(float x, float y, float z)
{
	this->x = x;
	this->y = y;
	this->z = z;
}
Vector3D::~Vector3D()
{
}

float Vector3D::SquaredLength() const
{
	
	return (x * x + y * y + z * z);
}

float Vector3D::Length() const
{
	return sqrt(x*x + y*y + z*z);
}
Vector3D Vector3D::Normalized()
{
	return *(this)/Length();
}




// Operators Overload
bool Vector3D::operator==(const Vector3D& v) const
{
	return v.x == x && v.y == y && v.z == z;
}



Vector3D Vector3D::operator / (float s) const
{
	return Vector3D(x / s, y / s, z / s);
}

Vector3D Vector3D::operator+(const Vector3D& v) const
{
	return Vector3D(x + v.x, y + v.y, z + v.z);
}

Vector3D Vector3D::operator-(const Vector3D& v) const
{
	return Vector3D(x - v.x, y - v.y, z - v.z);
}

// dot product, producto escalar
float Vector3D::DotProduct(const Vector3D& v)
{
	return (x*v.x + y*v.y + z*v.z);
}

// vector by factor k
Vector3D Vector3D::operator*(const float k) const
{
	return Vector3D(x * k, y * k, z * k);
}

// cross product, producto vectorial
Vector3D Vector3D::operator*(const Vector3D& s) const
{
	Vector3D v;
	v.x = y*v.z - z*v.y;
	v.y = z*v.x - x*v.z;
	v.z = x*v.y - y*v.x;
	return v;
}


